﻿/*********************************************************
*  @file    cm_lcd_7735s_demo.c
*  @brief   ML302 OpenCPU LCD example 
*  Copyright (c) 2020 China Mobile IOT.
*  All rights reserved.
*  created by XieGangLiang 2020/03/25
********************************************************/

#include "cm_main.h"
#include "cm_lcd.h"
static uint8_t g_lcd_index = 0xff;
extern lcdSpec_t cm_lcd_st7735s;
lcdSpec_t *cm_lcd_cfg_tab[] =
{
	(lcdSpec_t *)&cm_lcd_st7735s,
};
uint32_t cm_lcd_get_count(void)
{
    uint32_t count;
	count = sizeof(cm_lcd_cfg_tab) / sizeof(cm_lcd_cfg_tab[0]);
    return count;
}

lcdSpec_t *cm_lcd_get_spec_info(void)
{
    uint32_t count = 0;
    uint32_t i = 0;
    uint32_t lcm_dev_id = 0;
	count = cm_lcd_get_count();
    if ((count != 0) && (g_lcd_index == 0xff))
    {
        for (i = 0; i < count; i++)
        {
            if (cm_lcd_cfg_tab[i]->operation->readId)
            {
                lcm_dev_id = cm_lcd_cfg_tab[i]->operation->readId();              
            }
            if (lcm_dev_id == cm_lcd_cfg_tab[i]->dev_id)
            {
                g_lcd_index = i;
                return cm_lcd_cfg_tab[g_lcd_index];
            }
        }
    }
    else if (g_lcd_index != 0xff)
    {
        return cm_lcd_cfg_tab[g_lcd_index];
    }
    return NULL;
}